package com.financing.wap.weixin.handle;

import java.io.File;
import java.util.Date;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.financing.wap.service.IDstUserInfoService;
import com.financing.wap.util.DateUtil;
import com.financing.wap.util.PropertiesUtils;
import com.financing.wap.weixin.resp.Image;
import com.financing.wap.weixin.resp.ImageMessage;
import com.financing.wap.weixin.resp.TextMessage;
import com.financing.wap.weixin.test.WXBizMsgCrypt;
import com.financing.wap.weixin.util.MessageUtil;
import com.financing.wap.weixin.util.XMLParse;

/**
 * 自定义菜单 - 生成海报
 * 
 * @author lisu
 *
 */
@Service("createPosterHandler")
public class CreatePosterHandler implements MessageHandler {
	
	Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	IDstUserInfoService dstUserInfoService;
	
	private String wxxf_path =  PropertiesUtils.getValue("wxxf_path");
	
	@Override
	public String messageHandler(Map<String, String> requestMap) throws Exception {
			// 发送方帐号（open_id）
			String fromUserName = requestMap.get("FromUserName");
			
			// 公众帐号
			String toUserName = requestMap.get("ToUserName");
			
			ImageMessage imageMessage =  new ImageMessage();
			imageMessage.setToUserName(fromUserName);
			imageMessage.setFromUserName(toUserName);
			imageMessage.setCreateTime(new Date().getTime());
			imageMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_IMAGE);
			Image image = new Image();
			imageMessage.setImage(image);

			// 将文本消息对象转换成xml字符串
			return MessageUtil.imageMessageToXml(imageMessage);
	}

	public String sendMessage(String fromUserName, String toUserName,String message) {
		// 返回   5分钟获取一次
		TextMessage textMessage = new TextMessage();  
		textMessage.setToUserName(fromUserName);  
		textMessage.setFromUserName(toUserName);  
		textMessage.setCreateTime(new Date().getTime());  
		textMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_TEXT);  
		textMessage.setFuncFlag(0);  
		// 由于href属性值必须用双引号引起，这与字符串本身的双引号冲突，所以要转义  
		textMessage.setContent(message);  
		// 将文本消息对象转换成xml字符串  
		return MessageUtil.textMessageToXml(textMessage);
	}
	@Override
	public void messageSubsequentHandler(Map<String, String> requestMap) {
		// TODO Auto-generated method stub
	}
}
